package com.pat.web.controller;

import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.jfinal.core.Controller;
import com.pat.common.Constants;
import com.pat.web.ApiResponse;
import com.pat.web.model.Backgroundimage;

public class BackgroundimageController extends Controller {

	public void getBackgroundImage() {
		ApiResponse response = new ApiResponse();
		Long userId = getAttr(Constants.LOGIN_USER_ID);
		List<Backgroundimage> backgroundimages = Backgroundimage.dao
				.find("SELECT * FROM backgroundimage WHERE user_id = ? OR system = 1 ORDER BY system DESC", userId);
		response.setData(backgroundimages);
		response.setStatusCode("0000");
		renderJson(JSON.toJSONString(response, SerializerFeature.WriteDateUseDateFormat));
	}

	public void addBackgroundImage() {
		ApiResponse response = new ApiResponse();
		String imgUrl = getPara("imgUrl");
		Long userId = getAttr(Constants.LOGIN_USER_ID);
		new Backgroundimage().setImgUrl(imgUrl).setSystem(0).setUserId(userId).setCreateTime(new Date()).save();
		response.setData("success");
		response.setStatusCode("0000");
		renderJson(response);
	}
}
